package com.haixiaoke.saas.enterprise.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.order.domain.OrderChargeItem;
import com.haixiaoke.saas.order.service.IOrderChargeItemService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haixiaoke.saas.system.BaseController;

/**
 * 订单收费项目及价格Controller
 * 
 * @author panda
 * @date 2024-04-03
 */
@RestController
@RequestMapping("/business/item")
public class EnterpriseOrderChargeItemController extends BaseController {
    @Autowired
    private IOrderChargeItemService orderChargeItemService;

    /**
     * 查询订单收费项目及价格列表
     */
    @PreAuthorize("@ss.hasPermi('business:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderChargeItem orderChargeItem) {
        startPage();
        List<OrderChargeItem> list = orderChargeItemService.selectOrderChargeItemList(orderChargeItem);
        return getDataTable(list);
    }

    /**
     * 导出订单收费项目及价格列表
     */
    @PreAuthorize("@ss.hasPermi('business:item:export')")
    @Log(title = "订单收费项目及价格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderChargeItem orderChargeItem) {
        List<OrderChargeItem> list = orderChargeItemService.selectOrderChargeItemList(orderChargeItem);
        ExcelUtil<OrderChargeItem> util = new ExcelUtil<OrderChargeItem>(OrderChargeItem.class);
        util.exportExcel(response, list, "订单收费项目及价格数据");
    }

    /**
     * 获取订单收费项目及价格详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:item:query')")
    @GetMapping(value = "/{chargeId}")
    public AjaxResult getInfo(@PathVariable("chargeId") Long chargeId) {
        return success(orderChargeItemService.selectOrderChargeItemByChargeId(chargeId));
    }

    /**
     * 新增订单收费项目及价格
     */
    @PreAuthorize("@ss.hasPermi('business:item:add')")
    @Log(title = "订单收费项目及价格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderChargeItem orderChargeItem) {
        return toAjax(orderChargeItemService.insertOrderChargeItem(orderChargeItem));
    }

    /**
     * 修改订单收费项目及价格
     */
    @PreAuthorize("@ss.hasPermi('business:item:edit')")
    @Log(title = "订单收费项目及价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderChargeItem orderChargeItem) {
        return toAjax(orderChargeItemService.updateOrderChargeItem(orderChargeItem));
    }

    /**
     * 删除订单收费项目及价格
     */
    @PreAuthorize("@ss.hasPermi('business:item:remove')")
    @Log(title = "订单收费项目及价格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chargeIds}")
    public AjaxResult remove(@PathVariable Long[] chargeIds) {
        return toAjax(orderChargeItemService.deleteOrderChargeItemByChargeIds(chargeIds));
    }
}
